//
//  RCDLikeItemPopView.m
//  SchoolHelper
//
//  Created by  任辰东 on 2018/12/19.
//  Copyright © 2018 JSY. All rights reserved.
//

#import "RCDLikeItemPopView.h"
#import "RCDBaseLayoutView.h"

@interface RCDLikeItemPopView ()
@property (nonatomic, strong) NSArray<NSString *> *dataSourceArray;
@property (nonatomic, assign) AligmentType type;
@end

@implementation RCDLikeItemPopView

- (instancetype)initWithDataSourceArray:(NSArray<NSString *> *)dataArray AligmentType:(AligmentType)type
{
    if (self = [super init]) {
        _dataSourceArray = dataArray;
        _type = type;
        [self setupViews];
    }
    return self;
}

- (void)setupViews
{
    //    [self.wrapView addSubview:self.cancelBtn];
    
    RCDBaseLayoutView *bufferView;
    for (NSInteger i = 0; i < self.dataSourceArray.count; i ++) {
        
        RCDBaseLayoutView *itemView = [RCDBaseLayoutView new];
        itemView.backgroundColor = UIColorFromHex(0XFFFFFF);
        itemView.isHighlight = YES;
        itemView.tag = i;
        [itemView setTouchDownTarget:self action:@selector(itemViewClicked:)];
        [self.wrapView addSubview:itemView];
        
        if (i == self.dataSourceArray.count - 1) {
            [itemView addBottomLine];
        }else{
            [itemView addBottomLineWithEdge:UIEdgeInsetsMake(0, 15, 0, 15)];
        }
        
        UILabel *titleLabel = [UILabel new];
        titleLabel.text = self.dataSourceArray[i];
        titleLabel.font = UIFontSize(15);
        titleLabel.textColor = UIColorFromHex(0X333333);
        if (_type == AligmentTypeCenter) {
            titleLabel.textAlignment = NSTextAlignmentCenter;
        }else{
            titleLabel.textAlignment = NSTextAlignmentLeft;
        }
        
        [itemView addSubview:titleLabel];
        
        [itemView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            if (!bufferView) {
                make.top.equalTo(self.wrapView.mas_top);
            }else{
                make.top.equalTo(bufferView.mas_bottom);
            }
            make.left.equalTo(self.wrapView).offset(0);
            make.right.equalTo(self.wrapView).offset(-0);
            
            
            if (i == self.dataSourceArray.count - 1) {
                make.bottom.equalTo(self.wrapView.mas_bottom).offset(kBottomOffset);
            }
            
            make.height.mas_equalTo(50);
        }];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.equalTo(itemView);
        }];
        
        bufferView = itemView;
        
    }
    
    //    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    //
    //        make.top.equalTo(bufferView.mas_bottom).offset(10);
    //        make.left.right.equalTo(self.wrapView);
    //        make.height.mas_equalTo(45);
    //        make.bottom.equalTo(self.wrapView.mas_bottom).offset(kBottomOffset);
    //    }];
}

- (void)itemViewClicked:(RCDBaseLayoutView *)clickedView
{
    [self dismiss];
    if (self.didSelectedIndex) {
        self.didSelectedIndex(clickedView.tag);
    }
}
@end
